---@class ClientItemData
---@field New fun(itemId:number,itemModelId:number,num:number,isCopyCfg:number):ClientItemData
ClientItemData = Class("ClientItemData")
function ClientItemData:ctor(itemId,itemModelId,num,isCopyCfg)
    self:Set(itemId,itemModelId,num,isCopyCfg)
end
function ClientItemData:Set(itemId,itemModelId,num,isCopyCfg)
    self.itemId = tostring(itemId)
    self.itemModelId = itemModelId
    self.num = tonumber(tostring(num))
    self.tabType = 0
    self.bagId = 0 --背包堆叠区分的id
    self.isInvalid = nil
    if isCopyCfg then
        self:InitCfg()
    end
end

function ClientItemData:InitCfg()
    local cfg = dataTable.getDataTableByStringId("t_item",self.itemModelId)
    if not cfg then
        self.isInvalid = true
        logError("找不到配置表t_item:"..self.itemModelId)
        return
    end
    self.name = getLanguage(cfg.f_ItemName);
    self.itemType = cfg.f_BagType;
    self.quality = cfg.f_Quality;
    self.icon = cfg.f_Icon;
    self.desc = getLanguage(cfg.f_Desc);
    self.itemFunction = cfg.f_ItemFunction;
    self.scriptId = cfg.f_ScriptId;
    self.cornerMark = cfg.f_CornerMark
    self.itemBag = cfg.f_ItemBag;
end
function ClientItemData:SetBagId(bagId)
    self.bagId = bagId
end
function ClientItemData:SetTabType(tabType)
    self.tabType = tabType
end
function ClientItemData:SetNum(num)
    self.num = tonumber(tostring(num))
end

---@class ClientEquipData
---@field New fun(itemId:number,itemModelId:number,num:number,isCopyCfg:number):ClientEquipData
ClientEquipData = Class("ClientEquipData")
function ClientEquipData:ctor(itemId,itemModelId,num,isCopyCfg)
    self:Set(itemId,itemModelId,num,isCopyCfg)

end
function ClientEquipData:Set(itemId,itemModelId,num,isCopyCfg)
    self.itemId = itemId and tostring(itemId) or nil
    self.itemModelId = itemModelId
    self.num = tonumber(tostring(num))
    self.tabType = 0
    self.bagId = 0 --背包堆叠区分的id
    self.curRfLevel = 0
    self.maxRfLevel = 0
    self.exp = 0
    self.partnerId = nil
    self.random = {};
    self.power = 0
    self.isInvalid = nil
    if isCopyCfg then
        self:InitCfg()
    end
end
function ClientEquipData:InitCfg()
    local equip = dataTable.getDataTableByStringId("t_equip",self.itemModelId)
    if not equip then
        self.isInvalid = true
        logError("找不到配置表t_equip:"..self.itemModelId)
        return
    end
    self.name = getLanguage(equip.f_EquipName);
    self.tabType = EnumConst.ItemTableEnum.Equip;
    self.itemType = EnumConst.ItemTypeEnum.Equip;
    self.heroType = equip.f_EquipHeroType;
    self.icon = equip.f_EquipSuitlcon;
    self.level = equip.f_EquipLv;
    self.part = equip.f_EquipType;
    self.partName = getLanguage("EquipType"..equip.f_EquipType);
    self.quality = equip.f_EquipQuality;
    self.suit = equip.f_EquipSuit;
    self.desc = getLanguage(equip.f_EquipDesc);
    self.baseAttr = decodeJsonStrToTabel(equip.f_EquipBasic);
    self.upTargetId = equip.f_QualityUpTarget
    self.upNeedItem = equip.f_QualityUpCost
    self.attribute = {};
    local attrs = self.baseAttr
    if attrs then
        for i=1,#attrs do
            for key, value in pairs(attrs) do
                if type(value) == "number" then
                    self["attribute"][key] = value
                else
                    self["attribute"][value[1]] = value[2]
                end
            end
        end
    end
end
function ClientEquipData:SetNum(num)
    self.num = tonumber(tostring(num))
end
function ClientEquipData:AddNum(num)
    self.num = self.num + tonumber(tostring(num))
end
function ClientEquipData:SetRefine(level,exp)
    self.curRfLevel = level
    self.exp = exp
end
function ClientEquipData:SetBagId(bagId)
    self.bagId = bagId
end
function ClientEquipData:SetTabType(tabType)
    self.tabType = tabType
end
function ClientEquipData:SetPartnerId(partnerId)
    if partnerId then
        self.partnerId = tostring(partnerId)
    else
        self.partnerId = nil
    end

end
function ClientEquipData:SetPower(power)
    self.power = power
end
